import pymongo
 
myclient = pymongo.MongoClient("mongodb://localhost:27017/")
mydb = myclient["my_db_1"]
mycol = mydb["col_2"]

# 查询并修改数据
# myquery = { "name": "laoweng1" }
# newvalues = { "$set": { "age": 12345 } }
 
# mycol.update_many(myquery, newvalues)
 
# 输出修改后的  "sites"  集合
# for x in mycol.find():
    # print(x)

# 排序
# mydoc = mycol.find().sort("name",-1).limit(2)
# for x in mydoc:
    # print(x)
    
# 删除文档
# myquery = { "name": "laoweng1" }    
# x = mycol.delete_many(myquery)
# print(x)
# print(x.deleted_count, "个文档已删除")

# 删除集合
mycol.drop()